﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Lib.Data;
using Lib.Utilities;
using Lib.Helper;

/// <summary>
/// Summary description for ht
/// </summary>
public class ht
{
    public static DataTable P_LOGIN(string user, string pass)
    {
        DataTable b_dt = new DataTable();
        b_dt = DataSql.GetData(new object[] { user, pass }, "P_LOGIN");
        return b_dt;
    }

    //TRUONG
    public static DataTable Fdt_tt_truong_lke()
    {
        SessionHelper _nsd = new SessionHelper();
        DataTable b_dt = DataSql.GetData(_nsd.nsd, "PDM_TTTRUONG_LKE");
        return b_dt;
    }
    public static void PTT_TRUONG_NH(DataTable b_dt)
    {
        SessionHelper _nsd = new SessionHelper();
        if (LibTable.isNullOrEmtyTable(b_dt))
            throw new Exception("Không có dữ liệu");
        DataRow b_dr = b_dt.Rows[0];
        object[] pra = new object[] {_nsd.nsd, LibConvert.ObjectToString(b_dr["MA_TRUONG"]), LibConvert.ObjectToString(b_dr["TEN"]), LibConvert.ObjectToString(b_dr["sdt"]), LibConvert.ObjectToString(b_dr["diachi"])
        , LibConvert.ObjectToString(b_dr["email"]), LibConvert.ObjectToString(b_dr["web"]), LibConvert.ObjectToString(b_dr["hieu_truong"]), LibConvert.ObjectToString(b_dr["active"])};
        DataSql.ExeCuteProcedure(pra, "PDM_TRUONG_HOC_NH");
    }
    public static DataTable Fdt_TT_TRUONG_CT(string ma_truong)
    {
        SessionHelper _nsd = new SessionHelper();
        DataTable b_dt = DataSql.GetData(new object[] { _nsd.nsd, ma_truong }, "PDM_TRUONG_HOC_CT");
        return b_dt;
    }
    public static void PTT_TRUONG_XOA(string ma_truong)
    {
        SessionHelper _nsd = new SessionHelper();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma_truong }, "PDM_TT_TRUONG_XOA");
    }

    //MÃ TỈNH

    public static DataTable FDM_TINH_LKE()
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(_nsd.nsd, "PDM_TINH_LKE");
    }
    public static void FDM_TINH_NH(string nsd, string ma, string ten)
    {
        DataSql.ExeCuteProcedure(new object[] { nsd, ma, ten }, "PDM_TINH_NH");
    }
    public static void FDM_TINH_XOA(string nsd, string ma)
    {
        DataSql.ExeCuteProcedure(new object[] { nsd, ma }, "PDM_TINH_XOA");
    }

    //HUYEN
    public static DataTable FDM_HUYEN_LKE(string ma_tinh)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(new object[] { _nsd.nsd, ma_tinh }, "PDM_HUYEN_LKE");
    }
    public static string FDM_HUYEN_NH(string tinh_id,  string ma, string ten)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
       object[] val= DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, tinh_id, ma, ten }, "@ma", "PDM_HUYEN_NH");
       return val[0].ToString();
    }
    public static void FDM_HUYEN_XOA(string tinh_id, string ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, tinh_id, ma }, "PDM_HUYEN_XOA");
    }

    //XA
    public static DataTable FDM_XA_LKE(string ma_huyen)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(new object[] { _nsd.nsd, ma_huyen }, "PDM_XA_LKE");
    }
    public static string FDM_XA_NH(string idtinh, string huyenid, string ma, string ten)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, idtinh, huyenid, ma, ten }, "@ID", "PDM_XA_NH");
        return val[0].ToString();
    }
    public static void FDM_XA_XOA(string ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PDM_XA_XOA");
    }

    //dan toc
    public static DataTable FDM_DANTOC_LKE()
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData( _nsd.nsd , "PDM_DANTOC_LKE");
    }
    public static string FDM_DANTOC_NH(double ma, string ten)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma, ten }, "@ID", "PDM_DANTOC_NH");
        return val[0].ToString();
    }
    public static void FDM_DANTOC_XOA(double ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PDM_DANTOC_XOA");
    }
    //DOI TUONG
    public static DataTable FDM_DOITUONG_LKE()
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(_nsd.nsd, "PDM_DOITUONG_LKE");
    }
    public static string FDM_DOITUONG_NH(double ma, string ten, float hso)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma, ten, hso }, "@ID", "PDM_DOITUONG_NH");
        return val[0].ToString();
    }
    public static void FDM_DOITUONG_XOA(double ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PDM_DOITUONG_XOA");
    }

    //PHONG
    public static DataTable FDM_PHONG_LKE()
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(_nsd.nsd, "PDM_PHONG_LKE");
    }
    public static string FDM_PHONG_NH(double ma, string ten, float hso)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma, ten, hso }, "@ID", "PDM_PHONG_NH");
        return val[0].ToString();
    }
    public static void FDM_PHONG_XOA(double ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PDM_PHONG_XOA");
    }

    //
    //Nhà - kí túc xá

    public static DataTable FKTX_NHA_LKE()
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(_nsd.nsd, "PKTX_NHA_LKE");
    }
    public static string FKTX_NHA_NH(double ma, string ten)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma, ten }, "@ID", "PKTX_NHA_NH");
        return val[0].ToString();
    }
    public static void FKTX_NHA_XOA(double ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PKTX_NHA_XOA");
    }

    public static DataTable FKTX_PHONG_LKE(string ma_nha)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(new object[] { _nsd.nsd, ma_nha }, "PKTX_PHONG_LKE");
    }
    public static void FKTX_PHONG_XOA(double ma)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma }, "PKTX_PHONG_XOA");
    }
    public static string FKTX_PHONG_NH(string nhaid, string ma, string ten, string giuong)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        object[] val = DataSql.ExeCuteProcedure(new object[] { _nsd.nsd, ma, nhaid, ten, giuong }, "@ID", "PKTX_PHONG_NH");
        return val[0].ToString();
    }

    public static DataTable FKTX_DANGKY_LKE(string ma_phong)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        return DataSql.GetData(new object[] { _nsd.nsd, ma_phong }, "PKTX_DANGKY_LKE");
    }


    public static string FNS_NHANSU_NH(DataTable a)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        System.Data.DataColumn newColumn = new System.Data.DataColumn("NSD", typeof(System.Int64));
        newColumn.DefaultValue = Convert.ToInt64(_nsd.nsd);
        a.Columns.Add(newColumn);
        DataSql.ExeCuteProcedure(a, "PNS_NHANSU_NH");
        return "";
    }

    public static string FSV_SINHVIEN_NH(DataTable a)
    {
        SessionHelper _nsd = SessionHelper.GetSessionUser();
        System.Data.DataColumn newColumn = new System.Data.DataColumn("NSD", typeof(System.Int64));
        newColumn.DefaultValue = Convert.ToInt64(_nsd.nsd);
        a.Columns.Add(newColumn);
        DataSql.ExeCuteProcedure(a, "PSV_SINHVIEN_NHEXCEL");
        return "";
    }

    public static DataTable FDT_BACDT_LKE()
    {
        return DataSql.GetData("PDT_BACDT_LKE");
    }
    public static DataTable FDT_HTDT_LKE(string BACID)
    {
        return DataSql.GetData(BACID,"PDT_HINHTHUCDT_LKE");
    }
    public static DataTable FDT_NGANH_LKE(string HTDTID)
    {
        return DataSql.GetData(HTDTID, "PDT_NGANHDT_LKE");
    }
}